package model;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.annotation.JsonIgnore;

@XmlRootElement
public class User {
	private String lastname;
	private String firstname;
	private String nickname;
	private String password;
	private List<Rating> ratings;

	public User() {
		this.ratings = new ArrayList<Rating>();
	}

	public User(String lastname, String firstname, String nickname,
			String password) {
		this.lastname = lastname;
		this.firstname = firstname;
		this.nickname = nickname;
		this.password = password;
		this.ratings = new ArrayList<Rating>();
	}

	
	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setRatings(List<Rating> ratings) {
		this.ratings = ratings;
	}

	@XmlElement
	public String getLastname() {
		return lastname;
	}

	@XmlElement
	public String getFirstname() {
		return firstname;
	}

	@XmlElement
	public String getNickname() {
		return nickname;
	}

	@XmlTransient
	@JsonIgnore
	public String getPassword() {
		return password;
	}

	@XmlTransient
	public List<Rating> getRatings() {
		return ratings;
	}
	
	public boolean addRating(Rating r){
		return ratings.add(r);
	}
	
	public boolean deleteRating(int id) {
		return ratings.remove(getRatingById(id));
	}
	
	public Rating getRatingById(int id) {
		for(Rating r : ratings) {
			if(r.getId() == id) {
				return r;
			}
		}
		return null;
	}

	public Rating getRatingByMovie(Movie movie) {
		for(Rating r : ratings) {
			if(r.getMovie().equals(movie)) {
				return r;
			}
		}
		return null;
	}
}
